import { defineAsyncComponent } from 'vue'
import { UseUserStore } from './User'


export default {
    install: async function (app) {
        const User = UseUserStore();
        app.AddRouter([
            { path: '/login', component: () => import('./View/login.vue') },
        ]);

        app.Router.beforeEach((to, form, next) => {
            if (!User.token && to.path !== '/login') {
                next({
                    path: '/login',
                    query: { redirect: to.fullPath }
                })
            } else {
                next();
            }
        })

        // 注册组件
        app.RegistPluginCompontent('User.Logout', () => import('./View/User.vue'))

        app.RegistPluginEvent('User.Token', () => {
            return User.token
        });
    }
}